<template>
	<view class="mian">		
		<!-- #ifdef MP-WEIXIN -->
		<navbar  title="确认订单" :isGoBack="true" :isNotice="true" :bgColor="bgColor" :btnColors='btnColor' :visible="true" ></navbar>
		<!-- #endif -->	
		<view class="main-cur mt-30">			
			<view  class="flex justify-center align-center confirm-address-add"  style=" background: #fff; height: 80rpx; line-height: 2.55555556;" @click="bindAddress" v-if="comfirmInfo.address==''">
			  <iconfont class="mr-10" icon="icon-plus" color="#2B91ED" size="40rpx" />
			  <text class="text-df" style="color:#2B91ED">添加收货地址</text>
			</view>			   
			<view isLink v-if="comfirmInfo.address !=''" class="flex pt-10" @click="routeToNext(2)">
				<view class="flex mt-20 ml-20" style="align-items: flex-start;">
					<u-icon  color="#2979ff" size="28" :name="api_image+'/uplaod/20250605/417c8e8db3a23bbd88aabe623b6bb6d4a5fbdc01.png'"></u-icon>
				</view>
				<view class="flex flex-direction mt-20 ml-20" style="width: 486rpx;">						
					<view class="confirm-address-wrap-detail">{{comfirmInfo.address.province}}{{comfirmInfo.address.city}}{{comfirmInfo.address.region}}{{comfirmInfo.address.address}}</view>
					<view class="mt-20 mb-20" style="color: #555555;font-size: 28rpx;">					  
						<text>{{comfirmInfo.address.realname}}</text>
						<text  class="ml-10">{{comfirmInfo.address.phone}}</text>
					</view>		
				</view>
				<view class="flex mt-20 mr-10" style="font-size: 24rpx;color: #555555;align-items: flex-start;">
					<text>更换</text>
					<u-icon  color="#2979ff" size="18" :name="api_image+'/uplaod/20250605/b2a4aaeeebbaeffba70e4349ca3b2dc1f54cdcb1.png'"></u-icon>
			   </view>
			</view>						
		</view>	
		<view class="main-cur mt-20 pl-10 pb-20" style="padding-top: 35rpx;">
			<view class="address-title">
				商品明细
			</view>
			<view class="flex pl-35" v-for="(item,index) in shoppingCartList.list" :key="index">
				<view slot='icon' class="flex align-center">
					<image class="grid-img" :src="item.goods_image" bindtap="handleChangeGoods" 	mode="aspectFill"></image>
			    </view>
				<view class="confirm-wrap-content flex flex-direction justify-between ml-10" slot='content' style="width: 100%;">
					<view class="flex" style="flex-direction:column;margin-top: 20rpx;">
						<view class='flex align-center cell ellipsis-l2 text-content goods_title'>{{item.goods_title}}</view>						
					</view>
					<view class="goods_spec">
						<view class='flex align-center cell  text-content'>{{item.goods_spec}}</view>
						
					</view>
					<view class='confirm-wrap-price justify-between pr-20 align-center text-center'>
						<view class="">
							<text class="text-content" style="color: #FF2E00 ;font-size: 24rpx;">￥</text>	
							<text class="text-content" style="color: #FF2E00 ;">{{item.selling_price}}</text>	
						</view>											
						<view style="margin-right: 5rpx;color: #222222 ">×{{item.number}}</view>
					</view>
				</view>
			</view>					
			<view class="flex justify-end align-center p-30" style="border-top: 1rpx solid #f3f3f3;">
				<!-- <view class="comfirm_info text-bold">
					<text class="text-bold">共</text>
					<text class="text-red text-bold">{{comfirmInfo.allNumber}}</text>
					<text class="text-bold">件商品</text>
				</view> -->
				<text class="comfirm_info ml-15 text-bold">合计：</text>
				<view class="flex text-red  align-center text-center">
					<text style="font-size: 26rpx;font-weight: bold;color: #FF2E00;" class="mt-10">￥</text>
					<text style="font-weight: bold;font-size: 40rpx;color: #FF2E00;">{{comfirmInfo.storage_total_price}}</text>
				</view>
							 
			</view>			
		</view>	
		
		<view class="main-cur pt-20 flex mt-15 pl-30 pb-20 pr-20" style="flex-direction: row; justify-content: space-between;align-items: center;text-align: center;" v-if="comfirmInfo.coupon_list.length>0">
		   <view class="address-titles">
			   优惠券
		    </view>
		    <view class="flex align-items: center;text-align: center;"  @click="routeToCoupon" style="color: #36B3E9;">
				<view style="background: #36B3E9;border-radius: 6rpx 6rpx 6rpx 6rpx;height: 23px;" v-if="coupon_info" class="align-items: center;text-align: center;">
					<text class="mt-5 mb-5 ml-15 mr-15" style="font-weight: 400;font-size: 24rpx;color: #FFFFFF;">{{coupon_info}}</text>
				</view>
				<text class="ml-15" style="font-weight: bold;font-size: 32rpx;color: #36B3E9;">-￥{{discountPrice}}</text>
				<u-icon name="arrow-right" color="#36B3E9" size="17"></u-icon>
			</view>		    
		</view>
		
		
	    <view class="main-cur pt-20 flex mt-15 pl-30 pb-20" style="padding-top: 35rpx;">
			<view class="flex mt-15 justify-between" style="width: 100%;">
				<view class="address-titles">订单备注</view>
				<input  v-model="remark" class="uni-input mr-30 text-right"  placeholder="50字以内（选填）"  />	
			</view>			
		</view>			
		<view class="flex mb-30" style=""></view>		 		
		<!-- 地址信息 -->
		<biz-address  :show="showSelection" ref="goodsSpec" @chooseCancel="chooseCancel"  @chooseaddess='chooseaddess'></biz-address>	  
		<!-- 结算信息 -->
		<t-submit-bar :show="showPay" :maskClosable="showSelection"  :setting_money="comfirmInfo.allMoney+''"   @confirm="wxconfirm"  :type="settle_type"></t-submit-bar>	
	     <!-- 优惠券信息 -->
	     <biz-coupon  :show="showcoupon" ref="couponSpec" @CancelCoupon="CancelCoupon" @chooseCoupon='chooseCoupon'></biz-coupon>
	     
	</view>
</template>

<script>
	import address from "@/components/address/index.vue";
	import submit from "@/components/submit-bar/index.vue";
	import picker from "@/components/date-picker/index.vue";
	import coupon from "@/components/coupon/index.vue";

	export default {
		components: {
		   "biz-address": address,
		   "t-submit-bar": submit,
		   "date-picker": picker,
		   "biz-coupon": coupon,
		},
		data () {
			return {	
				...getApp().globalData.config,
				value:'',
				pay_types:1,			
				showSelection:false,
				settle_type:5,
				showPay:true,
				shopInfo:{},
				comfirmInfo:{
					address:{
					  realname:''	
					}
				},
				shoppingCartList: [],
				remark:"",
				quick_info:{},
				total_money:'0.00',
				allMoney:"0.00",				
				discountId:'',
				current: 1,
				addressId:'',
				info:{
				},
				carIds:'',
				discountPrice:0.00,
				coupon_name:'',
				showcoupon:false,
				redId:'',
				coupon_info:''
				
			}
		},
		onLoad(options) {	
			console.log('options',options)
			this.carIds=options.carIds
		    if(options.type==1){
		        this.quick_info=options.value
		    }
			if(options.type==2){
				this.quick_info=options.quick_info						 
			}		  
		},		      
		onShow(){
			this.redId=''
			this.discountPrice=0
		     this.getConfirm()
		},
		methods:{
			
			//付款方式
			pay_type(type){
				this.redId=''
				this.discountPrice=0
				this.pay_types=type
				this.getConfirm()
			},
			
			//跳转地址
			bindAddress(){
				let qucik = JSON.parse(this.quick_info)
				uni.navigateTo({
					url:"/pages/pagesuser/address/add-edit/index?type=c&quick_info="+this.quick_info
				})
			},
			//配件跳转
			doaccess(){
				let qucik = JSON.parse(this.quick_info)
				let defaultDateMultiple =JSON.stringify(this.defaultDateMultiple)
				// console.log('g',qucik.)
				// return
				uni.navigateTo({
					url:"/pages/pagesGoods/accessory/index?goodsId="+qucik.goodsId+"&quick_info="+this.quick_info+"&leaseId="+this.leaseId+"&defaultDateMultiple="+defaultDateMultiple
				})
			},
			//确认地址
			chooseaddess(events){
				this.addressId=events.id				
				this.getConfirm()
				this.showSelection=false
			},
			
			
			//选择收货地址
			routeToNext(type){	
				let that=this
				this.$http.AddressList({
					token:uni.getStorageSync('userInfo').token,
					addressId:this.addressId,					
					type,
					}).then(res=>{
					if(res.resCode=='9999'){
						this.showSelection=true
						that.$refs.goodsSpec.showSpecs(res.data)        
					}
				}) 			
			},
			
			
			routeToCoupon(type){
				let that=this				
				that.showcoupon=true
				console.log('coupon',that.comfirmInfo.coupon_list)
				that.$refs.couponSpec.showSpecs(that.comfirmInfo.coupon_list)  			
					
			},
			CancelCoupon(){
				this.showcoupon=false
			},
			chooseCoupon(events){
				this.showcoupon=false
				this.redId=events.id
				this.discountPrice=events.amount
				this.coupon_info=events.coupon_info
				console.log('events---',events);
				this.getConfirm()
					
				
			},	
			
			
			chooseCancel(){
				this.showSelection=false
			},
			
			
			//立即购买
			wxconfirm(){
				let shop_type= uni.getStorageSync('shop_type')				
				 let obj_data={
				     token:uni.getStorageSync('userInfo').token,
				     type:shop_type,
				     remark:this.remark,
				     redId:this.redId,
					 addressId:this.comfirmInfo.address.id,
				     order_type:this.pay_types,			   
				   }
					if(!obj_data.addressId){
						 uni.showToast({title:'请填写收货地址',icon:"none"}) 
						 return
					}
				     
				   if(shop_type=='carts'){ //购物车信息 
				     obj_data.carIds=this.carIds
					 console.log('obj_data',obj_data)
				     this.$http.orderSubmit(obj_data).then(res=>{
				       if(res.resCode=="9999"){
						   let order_no =res.data.pay_no
						   let goods_total=res.data.goods_total
						    uni.navigateTo({
						   		url:"/pages/pagesOrder/wxPay/index?pay_no="+order_no+"&goods_total="+goods_total+"&orderpay=1"
						   	})
						   
						   
						   // let obj={
							  //  token:uni.getStorageSync('userInfo').token,
							  //  pay_type:'wechat',
							  //  pay_no:res.data.pay_no
						   // }
						   // let order_no =res.data.pay_no
						   // let goods_total=res.data.goods_total
						   //  this.$http.orderpay(obj).then(rest=>{
							  //   if(rest.resCode=='9999'){
								 //    if(rest.resCode=='9999'){
									// 	uni.requestPayment({
									// 		provider: 'wxpay',
									// 		timeStamp: rest.data.timeStamp,
									// 		nonceStr: rest.data.nonceStr,
									// 		package: rest.data.package,
									// 		signType:rest.data.signType,
									// 		paySign: rest.data.paySign,
									// 		success: function (res) {
									// 			uni.navigateTo({
									// 				url:"/pages/pagesOrder/success/index?order_no="+order_no+"&goods_total="+goods_total+"&orderpay=1"
									// 			})
									// 		},
									// 		fail: function (err) {
									// 			uni.navigateTo({
									// 				url:"/pages/order/index"
									// 			})
									// 		},									
									// 	});								   								   
								 //    }else{
								 //   	   uni.showToast({title:res.resMessage,icon:"none"}) 
								 //    }								   
							  //   }else{
								 //   uni.showToast({title:res.resMessage,icon:"none"}) 
							  //   }							   
						   //  })	
				       }else{
				         uni.showToast({title:res.resMessage,icon:"none"})
				       }
				     })
				   }else{
				     obj_data.goodsInfo=this.quick_info
				     this.$http.orderSubmit(obj_data).then(res=>{
				       if(res.resCode=="9999"){
						   
						   let obj={
							   pay_type:'wechat',
							   pay_no:res.data.pay_no,
							   token:uni.getStorageSync('userInfo').token,
						   }
						   let order_no =res.data.pay_no
						   let goods_total=res.data.goods_total
						   
						   
						   uni.navigateTo({
						   url:"/pages/pagesOrder/wxPay/index?pay_no="+order_no+"&goods_total="+goods_total+"&orderpay=1"
						   })
						   
						   
						  //  this.$http.orderpay(obj).then(rest=>{
								// if(rest.resCode=='9999'){									
								// 	uni.requestPayment({
								// 	    provider: 'wxpay',
								// 		timeStamp: rest.data.timeStamp,
								// 		nonceStr: rest.data.nonceStr,
								// 		package: rest.data.package,
								// 		signType:rest.data.signType,
								// 		paySign: rest.data.paySign,
								// 		success: function (res) {
								// 			uni.navigateTo({
								// 				url:"/pages/pagesOrder/success/index?order_no="+order_no+"&goods_total="+goods_total+"&orderpay=1"
								// 			})
								// 		},
								// 		fail: function (err) {
								// 			uni.navigateTo({
								// 				url:"/pages/order/index"
								// 			})
								// 		},									
        //                             });
																   
								// }else{
								// 	uni.showToast({title:res.resMessage,icon:"none"}) 
								// }				   							   
						  //  })							
				       }else{
				         uni.showToast({title:res.resMessage,icon:"none"})
				       }
				     })
				   }	
			},	
					
					
			//立即购买 quick
			getConfirm(){     
			    let that=this
			    let shop_type= uni.getStorageSync('shop_type')		
				//立即购买 quick
				let obj_data={
					token:uni.getStorageSync('userInfo').token,
					addressId:this.addressId,
					orderType:this.pay_types,
					type:shop_type,
					carIds:this.carIds,
					redId:this.redId					
				}
				if(shop_type=='quick'){
					obj_data.goodsInfo=JSON.parse(this.quick_info)
				}
				
				console.log('obj_data',obj_data)
				
				this.$http.preView(obj_data).then(res=>{
			          if(res.resCode=="9999"){	
						  console.log('address',res.data.address)
					    that.addressId=res.data.address.id
						that.comfirmInfo=res.data  
						that.allMoney=res.data.allMoney         
						that.shoppingCartList=res.data
						that.total_money=res.data.allMoney	
						that.date_time=res.data.date_time			            
			          }else{
			            uni.showToast({title:res.resMessage,icon:"none"})
			            setTimeout(()=>{
			              uni.navigateBack({
			                delta: 1, // 返回上一级页面。
			                success: function() {
			                    console.log('成功！')
			                }
			              })
			            },2000)
			          }
			        })
			     
			},
		}
	}
</script>

<style>
	@import "./index.css";
</style>